#include <bits/stdc++.h>

# define INF 0x7fffffff  // 无穷大
typedef long long ll;

using namespace std;

class Solution {
public:
    string clearStars(string s) {
        vector<int> idxs[26];
        vector<int> delIdx;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '*') {
                for (int j = 0; j < 26; j++) {
                    if (idxs[j].size() == 0) continue;
                    delIdx.push_back(idxs[j].back());
                    idxs[j].pop_back();
                    break;
                }
            } else {
                idxs[s[i] - 'a'].push_back(i);
            }
        }
        string ans;
        int k = 0;
        sort(std::begin(delIdx), std::end(delIdx));
        for (int i = 0; i < s.size(); i++) {
            if (k < delIdx.size() && i == delIdx[k]) {
                k++;
                continue;
            }
            if (s[i] != '*') ans.push_back(s[i]);
        }
        return ans;
    }
};

int main() {
    Solution s;
    // std::cout << s.clearStars("aaba*") << std::endl;
    // cout << s.clearStars("de*") << endl;
    cout << s.clearStars("ee**") << endl;

    return 0;
}
